<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<!--<Select placeholder="请选状态" class="w200 m-r10" v-model="state">
					<Option value="-1">全部</Option>
					<Option value="1">出售</Option>
					<Option value="2">收购</Option>
				</Select>-->
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="getQuery">查询</Button>
			</Form>
		</div>
		<Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
		<Table stripe :columns="columns" ref="table" :data='list' :loading="loading"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery" :current.sync="page"></Page>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				dcShow: false,
				loading: true,
				jsonData: [],
				list: [], // 分享收益列表数据
				info: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				current: 1,
				downList: [],
				dataValue: ['', ''], // 时间段值
				addModal: false,
				tabsValue: 'buy',
				list2: [],
				state: '-1',
				columns: [{
						title: '发布时间',
						align: 'center',
						key: 'pushTime',
						sortable: true,
						render: (h, params) => {
							return h('div', params.row.pushTime == null ? '#' : this.stringToTime(params.row.pushTime))
						}
					},
					{
						title: '发布数量',
						align: 'center',
						key: 'pushNum',
						render: (h, params) => {
							return h('div', params.row.pushNum == null ? '0.00' : this.Fixed(params.row.pushNum));
						}
					},
					{
						title: '价格',
						align: 'center',
						key: 'price',
						render: (h, params) => {
							return h('div', params.row.price == null ? '0.00' : this.Fixed(params.row.price));
						}
					},
					{
						title: '库存',
						align: 'center',
						key: 'num',
						render: (h, params) => {
							return h('div', params.row.num == null ? '0.00' : this.Fixed(params.row.num));
						}
					},
					{
						title: '成交数量',
						align: 'center',
						key: 'dealNum',
						render: (h, params) => {
							return h('div', params.row.dealNum == null ? '0.00' : this.Fixed(params.row.dealNum))
						}
					},
					{
						title: '等级',
						align: 'center',
						key: 'flag',
						render: (h, params) => {
							return h('div', params.row.flag == null ? '0.00' : params.row.flag)
						}
					}
				],
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			})
			this.getQuery() // 查询直推奖励
		},
		methods: {
			exportData() {
				this.jsonData = [];
				this.dcShow = true;
				this.axios.get('/admin/trading/release', {
					params: {
						current: this.page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						typeId: this.state == -1 ? '' : this.state,
						startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
						endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.axios.get('/admin/trading/release', {
							params: {
								current: 1, // 当前页【可选，默认1】
								size: res.data.data.total, // 每页记录数【可选，默认20】
								typeId: this.state == -1 ? '' : this.state,
								startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
								endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
							}
						}).then(res => {
							if(res.data.code == 200) {
								this.downList = res.data.data.records;
								this.downList.forEach((row, index) => {
									this.downList[index].pushTime = this.downList[index].pushTime == null ? '#' : this.stringToTime(this.downList[index].pushTime);
									this.downList[index].pushNum = this.downList[index].pushNum == null ? '#' : this.Fixed(this.downList[index].pushNum);
									this.downList[index].price = this.downList[index].price == null ? '0.00' : this.Fixed(this.downList[index].price);
									this.downList[index].num = this.downList[index].dealNum == null ? '#' : this.Fixed(this.downList[index].num);
									this.downList[index].dealNum = this.downList[index].dealNum == null ? '#' : this.Fixed(this.downList[index].dealNum);
									this.downList[index].flag = this.downList[index].flag == null ? '#' : this.downList[index].flag;

									this.jsonData.push({
										pushTime: this.downList[index].pushTime,
										pushNum: this.downList[index].pushNum,
										price: this.downList[index].price,
										num: this.downList[index].num,
										dealNum: this.downList[index].dealNum,
										flag: this.downList[index].flag,
									})
								})
								let str = `发布时间,发布数量,价格,库存,成交数量,等级\n`;
								this.downLoad(this.jsonData, str, '发布记录');
							}
						})
					}
				})
			},
			// 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange
			},
			getQuery() {
				this.loading = true;
				this.axios.get('/admin/trading/release', {
					params: {
						current: this.page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						typeId: this.state == -1 ? '' : this.state,
						startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
						endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			cuctGetQuery(page) { // 分页查询直推奖励
				this.loading = true;
				this.axios.get('/admin/trading/release', {
					params: {
						current: page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						typeId: this.state == -1 ? '' : this.state,
						startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
						endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
		}
	}
</script>

<style>

</style>